# =============================================================================
#
# ANL.mk
# -- build ANL applications
#
# =============================================================================


SIM_ROOT ?= ../../simulator
include $(SIM_ROOT)/Defines.mk


# ==== Variables ==============================================================

OBJS := $(SRCS:.C=.o)
OBJS2 := $(SRCS2:.cpp=.o)
M4CFILES := $(SRCS:.C=.c)
M4HFILES := $(HEADERS:.H=.h)

CFLAGS := -g $(SIM_INCLUDES) $(DEBUGFLAGS) $(EXTRA_FLAGS) $(GCC_OPTIM3_LABEL) -DSIMULATOR -save-temps

M4 := m4 -I../m4_files


# ==== Rules ==================================================================

.PHONY: default clean m4file bcc $(PHONY_EXTRA)

default: bcc 

clean:
	$(RM) -r $(OBJS) $(OBJS2) $(M4CFILES) $(M4HFILES) \
              $(PROG) $(SIM_OUTPUT) $(OUTPUT_FILES)

%.o: %.c
	$(CC) $(CFLAGS) $(CFLAGS_FF) $(CFLAGS2) -c -o $@ $*.c

%.o: %.cpp
	$(CPP) $(CPPFLAGS) -c -o $@ $*.cpp

%.c: src/%.C
	$(M4) ../m4_files/c.m4.less src/$*.C > $*.c 

%.h: src/%.H
	$(M4) ../m4_files/c.m4.less src/$*.H > $*.h

m4file: $(M4CFILES) $(M4HFILES) 

bcc: m4file $(OBJS) $(OBJS2) $(EXTRA_LIBS2)
	$(LD) $(LDFLAGS) $(OBJS) $(OBJS2) $(SIM_LIBS) $(EXTRA_LDFLAGS) $(EXTRA_LIBS) $(EXTRA_LIBS2) -o $(PROG)
